package com.eric.rabbit.controller;

import com.eric.rabbit.entity.direct.DirectSender;
import com.eric.rabbit.entity.fanout.FanoutSender;
import com.eric.rabbit.entity.simple.SimpleSender;
import com.eric.rabbit.entity.topic.TopicSender;
import com.eric.rabbit.entity.work.WorkSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author:Eric
 * @date:2021/6/28
 */
@RestController
@RequestMapping("/rabbit")
public class Controller {

    @Autowired
    private SimpleSender simpleSender;

    @Autowired
    private WorkSender workSender;

    @Autowired
    private FanoutSender fanoutSender;

    @Autowired
    private DirectSender directSender;

    @Autowired
    private TopicSender topicSender;

    /**
     * 简单模式
     *
     * @return
     */
    @GetMapping("/simple")
    public ResponseEntity simple() {
        for (int i = 0; i < 5; i++) {
            simpleSender.send(i);
        }
        return ResponseEntity.ok(null);
    }

    /**
     * 工作模式
     *
     * @return
     */
    @GetMapping("/work")
    public ResponseEntity work() {
        for (int i = 0; i < 5; i++) {
            workSender.send(i);
        }
        return ResponseEntity.ok(null);
    }

    /**
     * 发布/订阅模式
     *
     * @return
     */
    @GetMapping("/fanout")
    public ResponseEntity fanout() {
        for (int i = 0; i < 5; i++) {
            fanoutSender.send(i);
        }
        return ResponseEntity.ok(null);
    }

    /**
     * 路由键模式
     *
     * @return
     */
    @GetMapping("/direct")
    public ResponseEntity direct() {
        for (int i = 0; i < 5; i++) {
            directSender.send(i);
        }
        return ResponseEntity.ok(null);
    }

    /**
     * 通配符
     *
     * @return
     */
    @GetMapping("/topic")
    public ResponseEntity topic() {
        for (int i = 0; i < 10; i++) {
            topicSender.send(i);
        }
        return ResponseEntity.ok(null);
    }

    /**
     * 相同的routeKey,不通的queue
     *
     * @return
     */
    @GetMapping("/sameKey")
    public ResponseEntity sameKey() {
        for (int i = 0; i < 10; i++) {
            topicSender.sameKeySend(i);
        }
        return ResponseEntity.ok(null);
    }
    /**
     * 相同的routeKey,不通的queue
     *
     * @return
     */
    @GetMapping("/sameKeyDire")
    public ResponseEntity sameKeyDire() {
        for (int i = 0; i < 3; i++) {
            directSender.sendSameKey(i);
        }
        return ResponseEntity.ok(null);
    }
}
